package com.rain.rainspringboot3.encryption.controller;


import com.rain.rainspringboot3.encryption.entity.UserDTO;
import com.rain.rainspringboot3.encryption.entity.UserVO;
import com.rain.rainspringboot3.encryption.service.User1Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户控制器
 */
@RestController
@RequestMapping("/api/users")
public class User1Controller {
    
    @Autowired
    private User1Service user1Service;
    
    /**
     * 创建用户
     */
    @PostMapping
    public boolean createUser(@RequestBody UserDTO userDTO) {
        // 创建用户（敏感数据会自动加密）
        return user1Service.createUser(userDTO);

    }
    
    /**
     * 获取用户详情
     */
    @GetMapping("/{id}")
    public UserVO getUser(@PathVariable Long id) {
        return user1Service.getUserById(id);
    }
    
    /**
     * 获取所有用户
     */
    @GetMapping
    public List<UserVO> getAllUsers() {
        return user1Service.getAllUsers();
    }
    
    /**
     * 根据用户名查询用户
     */
    @GetMapping("/username/{username}")
    public UserVO getUserByUsername(@PathVariable String username) {
        return user1Service.getUserByUsername(username);
    }
}